cmake_minimum_required(VERSION 3.5)

if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}   /MP")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MD")
endif ()

project(xd-multi LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
# They need to be set before the find_package(Qt5 ...) call.

#if(ANDROID)
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
#    if (ANDROID_ABI STREQUAL "armeabi-v7a")
#        set(ANDROID_EXTRA_LIBS
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
#    endif()
#endif()

find_package(Qt5 COMPONENTS Widgets WebEngine WebEngineWidgets WebChannel Sql Xml Network Gui Core REQUIRED)


get_target_property(_qmake_executable Qt5::qmake IMPORTED_LOCATION)
get_filename_component(_qt_bin_dir "${_qmake_executable}" DIRECTORY)

if(OS_WINDOWS)
  find_program(DEPLOYQT_EXECUTABLE windeployqt HINTS "${_qt_bin_dir}")
elseif(OS_MAC)
  find_program(DEPLOYQT_EXECUTABLE macdeployqt HINTS "${_qt_bin_dir}")
elseif(OS_LINUX)
else()
endif()


include_directories(../meeting-service)
include_directories(../libs/include)

file(GLOB_RECURSE _UI_FILES
  "*.ui"
)
source_group("Form Files" ${_UI_FILES})

file(GLOB _SRC_FILES
  "*.h"
  "*.cpp"

)



SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH    ${CMAKE_SOURCE_DIR}/bin)
message("--------------"${PROJECT_BINARY_DIR})
#SET_TARGET_PROPERTIES(dllname PROPERTIES ${RUNTIME_OUTPUT_DIRECTORY} ${PROJECT_BINARY_DIR}/bin)

if(OS_WINDOWS)

  file(GLOB_RECURSE _RES_FILES
      "*.qrc"
      "*.rc"
    )

add_executable(${PROJECT_NAME} WIN32
   ${_SRC_FILES}
   ${_UI_FILES}
   ${_RES_FILES}
 )


target_link_libraries(${PROJECT_NAME}
    PRIVATE
    Qt5::Widgets
    Qt5::WebEngine
    Qt5::WebEngineWidgets
    Qt5::WebChannel
    Qt5::Sql
    Qt5::Xml
    Qt5::Network
    Qt5::Gui
    Qt5::Core
    meeting_service
    )



add_custom_command(TARGET ${PROJECT_NAME}
    POST_BUILD
    COMMAND ${DEPLOYQT_EXECUTABLE}
    --no-svg
    --no-translations
    --no-compiler-runtime
    $<TARGET_FILE:${PROJECT_NAME}>
    )

endif()

if(OS_MAC)

  file(GLOB_RECURSE _RES_FILES
      "*.qrc"
      "*.rc"
    )

add_executable(${PROJECT_NAME} MACOSX_BUNDLE
   ${_SRC_FILES}
   ${_UI_FILES}
   ${_RES_FILES}
   ${_WEB_FILES}
 )


target_link_libraries(${PROJECT_NAME}
    PRIVATE
    Qt5::Widgets
    Qt5::WebEngine
    Qt5::WebEngineWidgets
    Qt5::WebChannel
    Qt5::Sql
    meeting_service
    )



add_custom_command(TARGET ${PROJECT_NAME}
    POST_BUILD
    COMMAND ${DEPLOYQT_EXECUTABLE}
    $<TARGET_FILE:${PROJECT_NAME}>
    -codesign="-"
    VERBATIM
    )

endif()


